#include <cstdio>

int main( )
{
    int t, n, m, i, j, cnt;
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%d", &n, &m);
        cnt = 0;
        for ( i = 0; i <= m / 5 && i <= n; i++ )
            for ( j = 0; j <= ( m - i * 5 ) / 2 && i + j <= n; j++ )
                if ( m - i * 4 - j == n )
                    cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}
